from flask_marshmallow import base_fields
from flask_restplus_patched import ModelSchema
from app.modules.common.schemas import BaseSchema

from .models import Menu

class BaseMenuSchema(ModelSchema):
    class Meta:
        model = Menu
        fields = (
            Menu.menu_id.key,
            Menu.menu_name.key,
            Menu.menu_url.key,
            Menu.menu_level.key,
            Menu.menu_status.key,
            Menu.parent_menu_id.key,
            Menu.menu_css.key,
        )

        dump_only = (
            Menu.menu_id.key,
        )

class MenuListSchema(ModelSchema):
    child_menu_list = base_fields.Nested(
        'BaseMenuSchema',
        many = True
    )
    class Meta(BaseMenuSchema.Meta):
        fields = BaseMenuSchema.Meta.fields+(
            "child_menu_list",
        )

class MenuSchema(BaseSchema):
    data = base_fields.Nested(
        MenuListSchema,
        many = True
    )
    class Meta:
        fields = BaseSchema.Meta.fields + (
            'data',
        )
